from telnetlib import DO

import numpy as np
from manimlib import *
from numpy import flip, insert
import math

LV, QL, QH, JH = '#75cfb8', '#bbdfc8', '#f0e5d8', '#ffc478'

class Cube_edges:
    def __init__(self,side_length):
        x = side_length / 2
        self.a, self.b, self.c, self.d = [x, x, x], [-x, x, x], [-x, -x, x], [x, -x, x]
        self.e, self.f, self.g, self.h = [x, x, -x], [-x, x, -x], [-x, -x, -x], [x, -x, -x]
    def get_object(self):
        a=self.a
        b=self.b
        c=self.c
        d=self.d
        e=self.e
        f=self.f
        g=self.g
        h=self.h
        return VGroup(
            Line(a, b), Line(b, c), Line(c, d), Line(d, a),
            Line(e, f), DashedLine(f, g), DashedLine(g, h), Line(h, e),
            DashedLine(c, g), Line(a, e), Line(b, f), Line(d, h)
        )

class p1(ThreeDScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        self.renderer.camera.light_source.move_to(3 * IN)
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        c=Cube_edges(4)
        self.add(c.get_object(),

                 )
        for i in [c.a,c.b,c.c,c.d,c.e,c.f,c.g,c.h]:
            self.add(Sphere(radius=0.15).move_to(i).set_color(DARK_BROWN))

def loop(color,li=[]):
    s3,s5=Square(3),Square(5)
    a,b,c,d=s5.get_boundary_point(UL),s5.get_boundary_point(UR),s5.get_boundary_point(DR),s5.get_boundary_point(DL)
    e,f,g,h=s3.get_boundary_point(UL),s3.get_boundary_point(UR),s3.get_boundary_point(DR),s3.get_boundary_point(DL)
    vg=VGroup(s3,s5,
              Line(a,e),
              Line(b,f),
              Line(c,g),
              Line(d,h),
              )
    li_p=[a,a,b,c,d,e,f,g,h]
    li_t=[]
    p=Polygon(li_p[li[0]],li_p[li[1]],li_p[li[2]],li_p[li[3]],li_p[li[4]],li_p[li[5]],li_p[li[6]],li_p[li[7]],li_p[li[8]]).set_color(color).set_stroke(width=8)
    vg.add(p)
    return vg

class p2(Scene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        self.add(
            loop(RED,[1,2,6,5,8,7,3,4,1]).scale(0.4).shift(LEFT*2.5+UP*1.5),
            loop(JH, [1, 2, 3, 4, 8, 7, 6, 5, 1]).scale(0.4).shift(UP*1.5),
            loop(YELLOW, [1, 5, 8, 7, 6, 2, 3, 4, 1]).scale(0.4).shift(RIGHT*2.5+UP*1.5),
            loop(LV, [1, 2,3,7,6,5,8,4, 1]).scale(0.4).shift(LEFT*2.5+DOWN*1.5),
            loop(BLUE, [1, 2,6,7,3,4,8,5,1]).scale(0.4).shift(DOWN*1.5),
            loop(PURPLE, [1, 5,6,2,3,7,8,4, 1]).scale(0.4).shift(RIGHT*2.5+DOWN*1.5),

        )
